package game.business

import game.Config
import game.enums.Direction
import game.model.View
import game.model.impl.Enemy

interface Move :View{
    /**
     * 可移动物体的方向
     */
    val currentDirection: Direction

    /**
     * 移动物体的速度
     */
    val speed:Int

    /**
     * 带边界检测的碰撞物检测
     */
    fun checkCollisionWithBoundary(view: View):Boolean{
        //未来的坐标
        var x: Int = this.x
        var y: Int = this.y
        //将要碰撞时去做判断
        when (currentDirection) {
            Direction.up -> y -= speed
            Direction.down -> y += speed
            Direction.left -> x -= speed
            Direction.right -> x += speed
        }

        //和边界检测
        if (x < 0 ||  x > Config.gameWidth - width) return true
        if (y < 0 ||  y > Config.gameHeight - height) return true


        //和碰撞物检测
        return checkCollision(x,y,this.width,this.height,view.x,view.y,view.width,view.height)
    }


    /**
     * 不带边界检测的碰撞物检测
     */
    fun checkCollision(view: View):Boolean{
        //未来的坐标
        var x: Int = this.x
        var y: Int = this.y
        //将要碰撞时去做判断
        when (currentDirection) {
            Direction.up -> y -= speed
            Direction.down -> y += speed
            Direction.left -> x -= speed
            Direction.right -> x += speed
        }

        //和碰撞物检测
        return checkCollision(x,y,this.width,this.height,view.x,view.y,view.width,view.height)
    }

}